#define ElemType int

typedef struct ListNode List_Node;

struct ListNode* deleteDuplicates(struct ListNode* head);

struct ListNode* deleteDuplicates2(struct ListNode* head);

#include "common.h"

int main()
{
	return 0;
}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

struct ListNode* deleteDuplicates(struct ListNode* head)
{
	if (!head)
		return NULL;

	List_Node aux = { 0, head };
	List_Node* head_aux = &aux;
	for (List_Node* p = head_aux; head && head->next;) {
		if (head->val == head->next->val) {
			int val = head->val;
			printf("val %d\n", val);
			while (head && head->val == val) {
				p->next = head->next;
				printf("head->val %d\n", head->val);
				free(head);
				head = p->next;
			}
		} else
			p = head, head = head->next;
	}

	return aux.next;
}

struct ListNode* deleteDuplicates2(struct ListNode* head)
{
	//List_Node head_aux = { 0, head };

	for (List_Node* p = head; p; p = p->next)
		while (p->next && p->next->val == p->val) {
			List_Node* next = p->next;
			p->next = next->next;
			free(next);
		}

	//return head_aux.next;
	return head;
}
